package uz.edo.db.bean;

import java.util.Set;

import java.util.List;
import java.util.LinkedList;
import java.util.HashSet;
import java.util.Iterator;
import uz.edo.db.utils.DBObject;

/**
 * Created by IntelliJ IDEA.
 * User: said
 * Date: 1/14/12
 * Time: 1:44 AM
 * To change this template use File | Settings | File Templates.
 */
public class Role extends DBObject{
    private String name;
    private String description;
    private Set privileges;
    private String privilegesStr;
    private List<Privilege> privilegeList;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Set getPrivileges() {
        return privileges;
    }

    public void setPrivileges(Set privileges) {
        this.privileges = privileges;
    }

    public String getPrivilegesStr() {
        Iterator iterator = privileges.iterator();
        if(privilegeList == null)
            privilegeList = new LinkedList<Privilege>();
        else if (privilegeList.size() > 0)
            privilegeList.clear();
        int i = 0;
        while (iterator.hasNext()){
            Privilege privilege = (Privilege)iterator.next();
            privilegeList.add(privilege);
            String value = privilege.getName();
            if(i++ > 0)
                privilegesStr += ", " + value;
            else
                privilegesStr = value;
        }
        return privilegesStr;
    }

    public List<Privilege> getPrivilegeList() {
        return privilegeList;
    }

    public void setPrivilegeList(List<Privilege> privilegeList) {
        if(privileges == null)
            privileges = new HashSet<Privilege>();
        for(Privilege privilege : privilegeList)
            privileges.add(privilege);
        this.privilegeList = privilegeList;
    }
}
